package org.testdemo1;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;

public class RecordElement {

	public Integer grade;
	public String date;
	public String playername;

	public byte[] serialize() {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DataOutputStream dos = new DataOutputStream(baos);
		try {
			dos.writeInt(grade);
			dos.writeUTF(date);
			dos.writeUTF(playername);
			baos.close();
			dos.close();
		} catch (Exception exc) {
			exc.printStackTrace();
		}
		return baos.toByteArray();
	}

	public static RecordElement deserialize(byte[] data) {
		ByteArrayInputStream bais = new ByteArrayInputStream(data);
		DataInputStream dis = new DataInputStream(bais);
		RecordElement recordElement = new RecordElement();
		try {
			recordElement.grade = dis.readInt();
			recordElement.date = dis.readUTF();
			recordElement.playername = dis.readUTF();
			bais.close();
			dis.close();
		} catch (Exception exc) {
			exc.printStackTrace();
		}
		return recordElement;
	}

	public RecordElement() {
	}

	public RecordElement(int grade) {
		this.grade = grade;
	}

	public RecordElement(String date) {
		this.date = date;
	}

	public RecordElement(String playername, int grade) {
		this.grade = grade;
		this.playername = playername;
	}

	public RecordElement(String playername, String date, int grade) {
		this.grade = grade;
		this.date = date;
		this.playername = playername;
	}

	public Integer getGrade() {
		return grade;
	}

	public void setGrade(Integer grade) {
		this.grade = grade;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getPlayername() {
		return playername;
	}

	public void setPlayername(String playername) {
		this.playername = playername;
	}

}
